package thinkingJava.chapter11;

import java.util.AbstractCollection;
import java.util.Iterator;

import thinkingJava.chapter14.Pet;
import thinkingJava.chapter14.Pets;

public class CollectionSequence extends AbstractCollection<Pet> {
	private Pet[] pets = Pets.createArray(8);

	public Iterator<Pet> iterator() {
		return new Iterator<Pet>() {
			private int index = 0;
			public boolean hasNext() {
				return index < pets.length;
			}
			public Pet next() {
				return pets[index++];
			}
			public void remove() {
				throw new UnsupportedOperationException();
			}
		};
	}

	public int size() {
		return pets.length;
	}
	public static void main(String[] args) {
		CollectionSequence cs = new CollectionSequence();
		InterfaceVsIterator.display(cs);
		InterfaceVsIterator.display(cs.iterator());
	}
}
